package com.ukao.pad.presenter;



import android.util.Log;

import com.ukao.pad.base.BasePresenter;
import com.ukao.pad.bean.AddClothingItem;
import com.ukao.pad.consts.Constant;
import com.ukao.pad.consts.SaveParamets;
import com.ukao.pad.retrofit.ApiCallback;
import com.ukao.pad.utils.Utils;
import com.ukao.pad.view.AddClothingView;

import java.util.HashMap;

import rx.Observable;

/**
 * Created by ukaodev on 2017/6/26.
 */

public class AddClothingPesenter extends BasePresenter<AddClothingView> {
    public static final int  BRAND=7;  //品牌
    public static final int FLAW=5;
    public static final int COLOR=4;//颜色
    public static final int AFTER_WASHING_EFFECT=6;
    public static final int  PROJECT=0;
    public static final int  SERVICE=2;
    public static final int  ANNEX=3;
    public static  final int ATTACH=8;
    public AddClothingPesenter(AddClothingView view) {
        attachView(view);
    }

    /**
     *项目       productId
     */
    public void projectData(HashMap  mHashMap,final  int pos) {
      mvpView.showLoading();
        Observable observable = null;
        switch (pos){
            case PROJECT :  /*项目*/
                observable=apiStores.project(Constant.createParameter(mHashMap));
                addSubscription(observable,mApiCallback );
                break;
            case  SERVICE: /*产品服务*/
                productService(mHashMap);
                break;
            case  ANNEX: /*附件*/
                productAnnex(mHashMap);
                break;
        }
    }

    /**
     * 请求洗后效果数据
     */
    public  void productAfterWashingEffect(HashMap mHashMap,final boolean isSearch){
        mvpView.showLoading();
        addSubscription(apiStores.productEffect(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            if(!isSearch)
                                mvpView.getProjectSuccess(model.getData());
                            else
                                mvpView.getSearchDataSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onNoNewWork() {
                    }
                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    /**
     * 请求瑕疵
     * @param mHashMap
     */
    public void  productFlaws(HashMap mHashMap,boolean isSearch){
        mvpView.showLoading();
        addSubscription(apiStores.productFlaw(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            if(!isSearch)
                                mvpView.getProjectSuccess(model.getData());
                            else
                                mvpView.getSearchDataSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onNoNewWork() {
                    }
                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }
    /**
     * 请求颜色
     * @param mHashMap
     */
    public  void  productColors(HashMap mHashMap,boolean isSearch){
        mvpView.showLoading();
        addSubscription(apiStores.productColor(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            if(!isSearch)
                                mvpView.getProjectSuccess(model.getData());
                            else
                                mvpView.getSearchDataSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onNoNewWork() {
                    }
                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    /**
     * 请求品牌
     * @param mHashMap
     */
 public  void  productBrand(HashMap mHashMap,boolean isSearch){
     mvpView.showLoading();
     addSubscription(apiStores.productBrand(Constant.createParameter(mHashMap)),
             new ApiCallback<AddClothingItem>() {
                 @Override
                 public void onSuccess(AddClothingItem model) {
                     if (model.getHttpCode()==200){
                         if(!isSearch)
                             mvpView.getProjectSuccess(model.getData());
                         else
                             mvpView.getSearchDataSuccess(model.getData());
                     }else{
                         mvpView.loadFail(model.getMsg());
                     }
                 }
                 @Override
                 public void onNoNewWork() {
                 }
                 @Override
                 public void onFinish() {
                     mvpView.hideLoading();
                 }

             });
 }
    public void productService(HashMap mHashMap ) {
        addSubscription(apiStores.productService(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            mvpView.getProjectSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onNoNewWork() {

                    }

                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }


    public void productAnnex(HashMap mHashMap ) {
        addSubscription(apiStores.productAnnex(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            mvpView.getProjectSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }


    public void productAddService(HashMap mHashMap ) {
        addSubscription(apiStores.productAddService(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {

                        if (model.getHttpCode()==200){

                            mvpView.getProjectSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }


                    }


                    @Override
                    public void onNoNewWork() {

                    }
                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    ApiCallback<AddClothingItem>    mApiCallback=new ApiCallback<AddClothingItem>() {
        @Override
        public void onSuccess(AddClothingItem model) {
            if (model.getHttpCode() == 200) {
                mvpView.getProjectSuccess(model.getData());
            } else {
                mvpView.loadFail(model.getMsg());
            }
        }
        @Override
        public void onNoNewWork() {

        }


        @Override
        public void onFinish() {
            mvpView.hideLoading();
        }

    };






}
